<template>
  <elm-page-bb id="init_name">
    <el-form  ref="model" :model="model" size="small" label-width="70px">
      <el-form-item label="用户名">
        <el-input v-model="model.name" :rules="[{ required: true, message: '当前用户名必须填写'}]"></el-input>
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input v-model="model.name" :rules="[{ required: true, message: '当前用户昵称必须填写'}]"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" :rows="2" v-model="model.remark"></el-input>
      </el-form-item>
    </el-form>
    <div style="margin:10px;color:#666;background:#FAFFBF;padding:10px;line-height:25px;">
      温馨提示：<br />
      1.用户名为姓名汉语拼音<br />
      2.用户昵称为汉语姓名<br />
    </div>
    <template #bottom>
      <elm-save-button type="success" size="small" @click="initName()" :data="model">立即保存</elm-save-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
    </elm-page-bb >
</template>

<script>
export default {
  extends: elmVueBase,

  data() {
    return {
      model:{id:null,name:null,nickname:null}
    }
  },
  created() {

  },
  methods: {
    initName() {
      this.$refs.model.validate(async valid => {
        if (valid) {
          elm.info.name = this.model.name;
          elm.info.nickname = this.model.nickname;
          console.log("user:"+JSON.stringify(elm.info.user))
          elm.info.user.id = this.userId;
          this.model.id = this.userId;
          let res = await elm.post("/business/my/initName", this.model);
          if (res.code == 0) {
            this.$message.success("保存成功");
            location.href = elm.settings.routefix + elm.info.system.path;
            this.close();
          } else {
            this.$message.error(res.msg);
          }
        } else {
          return
        }
      })
    }
  }
}
</script>
